package com.yjhb.android.sbz.v2.mvp.presenter

import com.yjhb.android.sbz.entity.TaskInfo
import com.yjhb.android.sbz.http.HttpObserver
import com.yjhb.android.sbz.http.HttpTool
import com.yjhb.android.sbz.v2.mvp.V2ConventionPresenter
import com.yjhb.android.sbz.v2.mvp.view.V2HomeView


/**
 *  创建者 zx
 *  创建时间 2021/4/12 16:53
 */
class V2HomePresenter(v: V2HomeView) : V2ConventionPresenter<V2HomeView>(v) {

    fun getFastList(current: Int, size: Int) {
        model?.let {
            HttpTool.request(it.getFastList(current, size), object : HttpObserver<List<TaskInfo>?>() {
                override fun onResult(data: List<TaskInfo>?) {
                    data?.let {
//                        val temp = mutableListOf<TaskInfo>()
//                        for (i in 1..10){
//                            temp.addAll(data)
//                        }
                        view?.onFastList(it, current == 1)
                    }
                }

                override fun onError(code: Int, msg: String) {
                    view?.onFailure(code, msg)
                }
            })
        }
    }

    fun getRecommendList(current: Int, size: Int) {
        model?.let {
            HttpTool.request(it.getHomeRecommendList(current, size), object : HttpObserver<List<TaskInfo>?>() {
                override fun onResult(data: List<TaskInfo>?) {
                    data?.let {
//                        val temp = mutableListOf<TaskInfo>()
//                        for (i in 1..10){
//                            temp.addAll(data)
//                        }
                        view?.onRecommendList(it, current == 1)
                    }
                }

                override fun onError(code: Int, msg: String) {
                    view?.onFailure(code, msg)
                }
            })
        }
    }
}